package com.service.impl;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.dao.StudentDao;
import com.entity.Master;
import com.entity.Student;
import com.github.pagehelper.PageHelper;
import com.service.StudentService;
import com.util.MD5Util;

@Service
@Transactional
public class StudentServiceImpl implements StudentService {
	@Autowired
	private StudentDao sd;

	// 登录
	@Override
	public Student studentLogin(String sno, String password) {
		return sd.studentLogin(sno, password);
	}

	// 注册
	@Override
	public boolean studentRegister(Student student) {
		sd.studentRegister(student);
		return true;

	}

	// 修改密码
	@Override
	public boolean updateStudentPassword(String sname, String password) {
		sd.updateStudentPassword(sname, password);
		return true;
	}

	// 通过学号查询个人信息
	@Override
	public Student selectStudentBySno(String sno) {
		return sd.selectStudentBySno(sno);
	}

	// 修改信息
	@Override
	public boolean updateStudent(Student student) {

		return sd.updateStudent(student);
	}

	// 添加学生
	@Override
	public boolean addStudent(Student student) {
		student.setSname(student.getSname());
		student.setPassword(student.getPassword());
		student.setSno(student.getSno());
		student.setSex(student.getSex());
		student.setPhone(student.getPhone());
		student.setSchool(student.getSchool());
		student.setEducation(student.getEducation());
		student.setMajor(student.getMajor());
		student.setGrade(student.getGrade());
		student.setSclass(student.getSclass());
		student.setDormitory(student.getDormitory());
		student.setDno(student.getDno());
		sd.addStudent(student);
		return true;
	}

	// 管理员查看所有学生（分页）
	@Override
	public List<Student> findAllStudents(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<Student> findAllStudents = sd.findAllStudents();
		return findAllStudents;
	}
	
	// 通过学号修改学生宿舍号
	@Override
	public boolean updateStudentDnoBySno(String sno,String dno) {
		return sd.updateStudentDnoBySno(sno,dno);
	}
	
	// 管理员多条件查询学生（分页）
	@Override
	public List<Student> findStudentByMultiple(Student student, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<Student> multiple = sd.findStudentByMultiple(student);
		return multiple;
	}

	// 通过学号删除学生
	@Override
	public int deleteStudentBySno( String sno) {
		return sd.deleteStudentBySno(sno);
	}

	// 通过宿舍号查找学生信息
	@Override
	public List<Student> findStudentByDno(String dno) {
		return sd.findStudentByDno(dno);
	}

	@Override
	public Student findPasswordByStudentName(String sname) {
		
		return sd.findPasswordByStudentName(sname);
	}

}
